var a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), e = getApp(), i = null;

Page({
    data: {
        kFootshow: !0,
        active: "0",
        id: "",
        banner: "",
        title: "",
        datas: [],
        categories: [],
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        show1: !1,
        noNotice: !1,
        article_pay: "",
        searchText: "",
        playInd: null,
        postStart: !1,
        sliderShow: !1
    },
    onLoad: function(a) {
        a.id && this.setData({
            id: a.id
        }), this.setData({
            options: a
        }), this.initData(), i = wx.createInnerAudioContext();
    },
    onReady: function() {},
    onShow: function() {
        this.getNetData(), this.init();
    },
    startPlayOrPause: function(e) {
        var s = this;
        return t(a.default.mark(function t() {
            var o, n, r, d;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (!(o = e.currentTarget.dataset.item).has_one_article_pay) {
                        a.next = 5;
                        break;
                    }
                    if (o.has_one_record) {
                        a.next = 5;
                        break;
                    }
                    return wx.navigateTo({
                        url: "/packageD/article/articleList/articleList?article_id=" + o.id
                    }), a.abrupt("return");

                  case 5:
                    return a.next = 7, s.checkPrivilege(o.id);

                  case 7:
                    if (n = a.sent, console.log(n), 0 != n.result) {
                        a.next = 14;
                        break;
                    }
                    return wx.showToast({
                        title: n.msg,
                        icon: "none",
                        duration: 1e3
                    }), a.abrupt("return");

                  case 14:
                    for (r = e.currentTarget.dataset.i, s.data.sliderShow || s.setData({
                        sliderShow: !0
                    }), s.data.playInd != r && (i.stop(), s.data.postStart = !1), d = 0; d < s.data.datas.length; d++) d == r ? (s.data.datas[d].playStatus = !0, 
                    i.src = encodeURI(o.audio_link), i.play()) : s.data.datas[d].playStatus = !1;
                    s.setData({
                        playInd: r,
                        datas: s.data.datas
                    });

                  case 19:
                  case "end":
                    return a.stop();
                }
            }, t);
        }))();
    },
    checkPrivilege: function(a) {
        return new Promise(function(t, i) {
            var s = e.getNetAddresss("plugin.article.api.article.get-article");
            e._getNetWork({
                url: s,
                data: {
                    article_id: a
                },
                success: function(a) {
                    var e = a.data;
                    e.result, t(e);
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        });
    },
    init: function() {
        var a = this;
        i.onCanplay(function() {}), i.onPlay(function() {
            console.log("开始播放"), console.log(i.duration), a.startPostMethod();
        }), i.onTimeUpdate(function() {
            setTimeout(function() {
                var t = i.currentTime / i.duration * 100, e = parseInt(t);
                a.setData({
                    valueSlmin: e,
                    audio_length: i.duration
                });
            }, 500);
        }), i.onEnded(function(t) {
            a.data.datas[a.data.playInd].playStatus = !1, a.setData({
                datas: a.data.datas
            }), a.data.postStart = !1;
        }), i.onError(function(a) {});
    },
    startPostMethod: function() {
        var a = this;
        if (0 == this.data.postStart) {
            var t = e.getNetAddresss("plugin.article.api.article.clickAudioViews");
            e._getNetWork({
                url: t,
                data: {
                    article_id: this.data.datas[this.data.playInd].id
                },
                success: function(t) {
                    var e = t.data;
                    1 == e.result && (console.log(a.data.datas[a.data.playInd]), a.data.datas[a.data.playInd].virtual_audio_views = e.data.virtual_audio_views, 
                    a.setData({
                        datas: a.data.datas
                    }));
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else console.log("暂停过 postStart = true");
    },
    pause: function(a) {
        var t = a.currentTarget.dataset.i;
        this.data.datas[t].playStatus = !1, this.data.postStart = !0, this.setData({
            datas: this.data.datas
        }), i.pause();
    },
    tapClose: function() {
        this.setData({
            sliderShow: !1
        });
    },
    sildein: function(a) {
        var t = a.detail.value / 100, e = this.data.audio_length * t;
        this.data.datas[this.data.playInd].playStatus = !1, this.setData({
            datas: this.data.datas
        }), i.seek(e), i.play();
    },
    changeSilde: function(a) {
        var t = a.detail, e = this.data.audio_length * (t / 100);
        this.data.datas[this.data.playInd].playStatus = !0, this.setData({
            datas: this.data.datas
        }), i.seek(e), i.play();
    },
    onHide: function() {
        i.stop(), i.destroy();
    },
    onUnload: function() {
        i.stop(), i.destroy();
    },
    onPullDownRefresh: function() {
        this.initData(), this.getNetData();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    shareTap: function(a) {
        console.log(a);
    },
    onShareAppMessage: function(a) {
        if (a.target.dataset.item && a.target && a) {
            var t = a.target.dataset.item, e = {
                title: t.title,
                id: t.id,
                img: t.thumb
            }, i = {
                title: e.title,
                path: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=".concat(e.id),
                imageUrl: e.img
            };
            if (this.data.options.taskID && (i.path += "&taskID=".concat(this.data.options.taskID, "&taskDay=").concat(this.data.options.taskDay, "&task_type=article")), 
            e) return i;
        }
    },
    onShareTimeline: function() {},
    tabrshowbtn: function(a) {
        a.detail && this.setData({
            kFootshow: !1
        });
    },
    initData: function() {
        i && i.stop(), this.setData({
            page: 1,
            total_page: 0,
            goload: !0,
            loading: !0,
            allLoaded: !1,
            isLoadMore: !0,
            datas: [],
            sliderShow: !1
        });
    },
    handSearch: function() {
        this.initData(), this.getNetData();
    },
    getNetData: function() {
        var a = this, t = {
            category_id: this.data.id,
            page: 1,
            keyword: this.data.searchText
        }, i = e.getNetAddresss("plugin.article.api.article.get-articles");
        e._getNetWork({
            url: i,
            data: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    noNotice: !1,
                    total_page: e.data.articles.last_page,
                    article_pay: e.data.article_pay
                }), a.data.total_page || a.setData({
                    total_page: 0
                }), e.data.categories.length <= 0 && a.setData({
                    noNotice: !0
                }), a.setData({
                    title: e.data.title,
                    datas: e.data.articles.data,
                    categories: e.data.categories
                }), console.log(a.data.datas), a.data.id && a.data.categories.forEach(function(t, e, i) {
                    t.id == a.data.id && a.setData({
                        active: e + 1
                    });
                }), wx.setNavigationBarTitle({
                    title: e.data.title
                })) : a.setData({
                    noNotice: !0
                }), wx.stopPullDownRefresh();
            },
            fail: function(a) {
                console.log(a), wx.stopPullDownRefresh();
            }
        });
    },
    gofufei: function() {
        wx.navigateTo({
            url: "/packageD/article/PayarticleList/PayarticleList"
        });
    },
    toNoticeInfo: function(a) {
        var t = a.currentTarget.dataset.item;
        t.has_one_article_pay ? t.has_one_record ? 1 == t.type ? this.data.options.taskID ? wx.navigateTo({
            url: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=".concat(t.id, "&taskID=").concat(this.data.options.taskID, "&taskDay=").concat(this.data.options.taskDay)
        }) : wx.navigateTo({
            url: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=" + t.id
        }) : this.data.options.taskID ? wx.navigateTo({
            url: "/packageA/member/article/articleContent/articleContent?article_id=".concat(t.id, "&taskID=").concat(this.data.options.taskID, "&taskDay=").concat(this.data.options.taskDay)
        }) : wx.navigateTo({
            url: "/packageA/member/article/articleContent/articleContent?article_id=" + t.id
        }) : wx.navigateTo({
            url: "/packageD/article/articleList/articleList?article_id=" + t.id
        }) : 1 == t.type ? this.data.options.taskID ? wx.navigateTo({
            url: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=".concat(t.id, "&taskID=").concat(this.data.options.taskID, "&taskDay=").concat(this.data.options.taskDay)
        }) : wx.navigateTo({
            url: "/packageA/member/course/VoiceDetail/VoiceDetail?article_id=" + t.id
        }) : this.data.options.taskID ? wx.navigateTo({
            url: "/packageA/member/article/articleContent/articleContent?article_id=".concat(t.id, "&taskID=").concat(this.data.options.taskID, "&taskDay=").concat(this.data.options.taskDay)
        }) : wx.navigateTo({
            url: "/packageA/member/article/articleContent/articleContent?article_id=" + t.id
        });
    },
    onClick: function(a) {
        var t = a.detail.index;
        this.initData(), 0 === t ? this.setData({
            id: ""
        }) : this.setData({
            id: this.data.categories[t - 1].id
        }), this.getNetData();
    },
    getMoreData: function() {
        var a = this;
        if (this.data.page !== this.data.total_page) if (this.data.page >= this.data.total_page) a.setData({
            loading: !0,
            allLoaded: !0
        }); else {
            a.setData({
                page: this.data.page + 1
            });
            var t = {
                category_id: this.data.id,
                page: this.data.page,
                keyword: this.data.searchText
            }, i = e.getNetAddresss("plugin.article.api.article.get-articles");
            e._getNetWork({
                url: i,
                data: t,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? a.setData({
                        total_page: e.data.articles.last_page,
                        loading: !1,
                        allLoaded: !1,
                        datas: a.data.datas.concat(e.data.articles.data)
                    }) : a.setData({
                        page: a.data.page - 1,
                        loading: !0,
                        allLoaded: !0,
                        isLoadMore: !1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    }
});